package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.CompanyNecessaryFieldAddDTO;
import org.jsola.hr.dto.CompanyNecessaryFieldUpdateDTO;
import org.jsola.hr.entity.CompanyNecessaryFieldDO;
import org.jsola.hr.query.CompanyNecessaryFieldQuery;
import org.jsola.hr.service.ICompanyNecessaryFieldService;
import org.jsola.hr.vo.CompanyNecessaryFieldVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 公司员工必填字段信息
 *
 * @author zhr
 */
@Component
public class CompanyNecessaryFieldTestHelper extends BaseTestHelper {
    
    @Autowired
    private ICompanyNecessaryFieldService companyNecessaryFieldService;

    /**
     * 生成add测试数据
     * @return CompanyNecessaryFieldAddDTO
     */
    public CompanyNecessaryFieldAddDTO getCompanyNecessaryFieldAddDTO(){
        CompanyNecessaryFieldAddDTO companyNecessaryFieldAddDTO = new CompanyNecessaryFieldAddDTO();
        companyNecessaryFieldAddDTO.setSort(SafeKit.getInteger(getRandomValue("int",10)));
        companyNecessaryFieldAddDTO.setIsEdit(SafeKit.getInteger(getRandomValue("int",2)));
        companyNecessaryFieldAddDTO.setFieldType(getRandomValue("int",2));
        companyNecessaryFieldAddDTO.setFieldCode(getRandomValue("varchar",32));
        companyNecessaryFieldAddDTO.setFieldName(getRandomValue("varchar",32));
        companyNecessaryFieldAddDTO.setIsNecessary(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        companyNecessaryFieldAddDTO.setIsOpen(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        companyNecessaryFieldAddDTO.setModuleName(getRandomValue("varchar",50));
        companyNecessaryFieldAddDTO.setModuleCode(getRandomValue("varchar",30));
        companyNecessaryFieldAddDTO.setCompanyId(getRandomValue("varchar",32));
        return companyNecessaryFieldAddDTO;
    }


    /**
     * 生成update测试数据
     * @return CompanyNecessaryFieldUpdateDTO
     */
    public CompanyNecessaryFieldUpdateDTO getCompanyNecessaryFieldUpdateDTO(CompanyNecessaryFieldVO companyNecessaryFieldVO){
        return companyNecessaryFieldService.selectDOById(companyNecessaryFieldVO.getId(), SITE_ID).to(CompanyNecessaryFieldUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return CompanyNecessaryFieldQuery
     */
    public CompanyNecessaryFieldQuery getCompanyNecessaryFieldQuery() {
        CompanyNecessaryFieldQuery companyNecessaryFieldQuery = new CompanyNecessaryFieldQuery();
        List<CompanyNecessaryFieldDO> companyNecessaryFieldDOList = companyNecessaryFieldService.list(new CompanyNecessaryFieldDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(companyNecessaryFieldDOList)) {
            CompanyNecessaryFieldDO companyNecessaryFieldDO = companyNecessaryFieldDOList.get(0);
            companyNecessaryFieldQuery = companyNecessaryFieldDO.to(CompanyNecessaryFieldQuery.class);
        }
        return companyNecessaryFieldQuery;
    }

    /**
     * 保存示例
     * @return CompanyNecessaryFieldVO
     */
    public CompanyNecessaryFieldVO saveCompanyNecessaryFieldExample(){
        CompanyNecessaryFieldAddDTO addDTO = this.getCompanyNecessaryFieldAddDTO();
        CompanyNecessaryFieldVO companyNecessaryFieldVO = companyNecessaryFieldService.save(addDTO,buildTokenUser());
        return companyNecessaryFieldVO;
    }


}

